package mns.modules.input.events;

import mns.*;

/**
 * 
 * @author Dan Moore
 *
 */
public class EventsModule implements MNSInputModule {
	
	private static enum Events {
		BIRTHDAY, ANNIVERSARY, HOLIDAY, VACATION, TVSHOW, OTHER
	}
	
	public String getName() {
		return "Generic Events Input Module";
	}
	
	public String getOptionsFormHTML() {
		String form = new String();
		
		form+="Title: <input type=\"text\" name=\"title\" value=\"Mom's Birthday!\" /><br>";
		//form+="Date: <input type=\"text\" name=\"date\" value=\"MM-DD-YYYY\" /><br>";
		
		form+="Event Types: <select name=\"type\">";
		form+="<optgroup label=\"Events\">";
		form+="<option value=\""+Events.BIRTHDAY+"\">Birthday</option>";
		form+="<option value=\""+Events.ANNIVERSARY+"\">Anniversary</option>";
		form+="<option value=\""+Events.HOLIDAY+"\">Holiday</option>";
		form+="<option value=\""+Events.VACATION+"\">Vacation</option>";
		form+="<option value=\""+Events.TVSHOW+"\">TV Show</option>";
		form+="<option value=\""+Events.OTHER+"\">TV Show</option>";
		form+="</optgroup></select>";
		
		return form;
	}

	public String getDescriptionHTML() {
		// TODO Auto-generated method stub
		return "";
	}
	
	private String getLongEventMsg(String title, Events type) {
		String msg = "Remember that the ";
		switch(type) {
			case BIRTHDAY:
				msg+="birthday ";
				break;
			case ANNIVERSARY:
				msg+="anniversary ";
				break;
			case HOLIDAY:
				msg+="holiday ";
				break;
			case VACATION:
				msg+="birthday ";
				break;
			case TVSHOW:
				msg+="tvshow ";
				break;
			case OTHER:
			default:
				msg+="event ";
				break;
		}
		msg+="titled \""+title+"\" is coming up!";
		return msg;
	}
	
	private String getShortEventMsg(String title, Events type) {
		String msg = "Reminder for ";
		switch(type) {
			case BIRTHDAY:
				msg+="birthday";
				break;
			case ANNIVERSARY:
				msg+="anniversary";
				break;
			case HOLIDAY:
				msg+="holiday";
				break;
			case VACATION:
				msg+="birthday";
				break;
			case TVSHOW:
				msg+="tvshow";
				break;
			case OTHER:
			default:
				msg+="event";
				break;
		}
		msg+=": "+title+".";
		return msg;
	}
	
	public MNSMessage getMessage(UserOptions opts) {
		String title = "";
		//String date = "";
		UserOption opt;
		Events type;
		MNSMessage msg = new MNSMessage();
		
		try {
			opt = opts.getOption("title");
			title = opt.getValue();
			//opt = opts.getOption("date");
			//date = opt.getValue();
			opt = opts.getOption("type");
			type = Events.valueOf(opt.getValue());
			msg = new MNSMessage(getLongEventMsg(title, type),getShortEventMsg(title, type));
		} catch(NullPointerException e) {
			System.err.println("Bad User Options, not getting msg.");
			return null;
		}
		
		return msg;
	}

	public NotificationType getType() {
		return NotificationType.SCHEDULED;
	}

}
